package cn.wizzer.app.onlyoffice.modules.services.impl;

import cn.wizzer.app.onlyoffice.modules.config.OnlyOfficeProperties;
import cn.wizzer.app.onlyoffice.modules.models.documentServer.DefaultDocumentWrapper;
import cn.wizzer.app.onlyoffice.modules.models.documentServer.Document;
import cn.wizzer.app.onlyoffice.modules.services.DocumentConfigurer;
import cn.wizzer.app.web.commons.base.Globals;
import cn.wizzer.app.web.commons.utils.DateUtil;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Times;

import java.util.Date;

@IocBean
public class DocumentConfigurerImpl implements DocumentConfigurer<DefaultDocumentWrapper> {
    @Inject
    private OnlyOfficeProperties onlyOfficeProperties;

    @Override
    public void configure(Document document, DefaultDocumentWrapper wrapper) {
        String fileName = wrapper.getFileName();
        Document.Permission permission = wrapper.getPermission();
        // 设置文件名称
        document.setTitle(fileName);
        // 设置访问地址
        document.setUrl(Globals.AppFileDomain+wrapper.getBusinessFileInfo().getFilePath());
        document.setUrl(Globals.AppDomain+"/download/file/"+wrapper.getBusinessFileInfo().getId());
        document.setFileType(wrapper.getBusinessFileInfo().getFileType().replace(".",""));
        Document.Info info = document.getInfo();
        info.setFavorite(wrapper.getFavorite());
        info.setOwner(wrapper.getBusinessFileInfo().getOperatorName());
        info.setUploaded(new Date(wrapper.getBusinessFileInfo().getOpAt() * 1000).toString());
        document.setKey(wrapper.getBusinessFileInfo().getId()+wrapper.getBusinessFileInfo().getOpAt());
        document.setPermissions(permission);
    }
}
